<template>
    <div>
        <table>
            <tr>
                <td>id</td>
                <td>分类</td>
                <td>修改</td>
                <td>删除</td>
            </tr>
            <tr v-for="i in list_1">
                <td>{{i.id}}</td>
                <td>{{i.name}}</td>
                <td>
                   <router-link :to="{path:'cate_put',query:{'id':i.id}}">修改</router-link>
                </td>
                <!-- <td>
                    <van-button @click="show__s(i.id)">修改</van-button>
                </td> -->

                <td>
                    <van-button @click="del(i.id)">删除</van-button>
                </td>
            </tr>
            <!-- <tr> -->
                    <!-- <td> -->
                            <!-- <van-pagination
                                v-model="currentPage"
                                :total-items='total'
                                :items-per-page='3'
                                @change='getlist'
                                force-ellipses
                            /> -->
                            
                    <!-- </td> -->
            <!-- </tr> -->
        </table>

        <button v-for="i in numm" @click="getlist(i)">{{i}}</button>
        <router-link :to="{path:'cate_add'}">添加分类</router-link>

        <!-- 分类名称:<input type="text" v-model="name">
        <button @click="add">添加</button> -->
         <!-- <van-button @click="show_s" class="tianjia">添加</van-button> -->
            <!-- 修改 v-show是隐藏 -->
            <!-- <div v-show="show"> 
                        名字<input type="text" v-model="name">
                        <van-button @click="put_cate">修改</van-button>
            </div> -->

            <!-- 添加 -->
             <!-- <div v-show="show_add"> 
                              <van-field v-model="from.name" label="名称"  placeholder="请输入用户名" />

                                <van-button @click="cate_add" class="tanjia11">添加</van-button>
            </div> -->
    </div>
</template>

<script>
    export default {
        data(){
            return{
                frm:{},
                // name:"",
                // show:0,
                // id:0,
                // show_add:0,
                from:{},
                name:"",
                list_1:[],
                currentPage:1,
                numm:0
            }
        },
        methods:{
            // show_s(){
            //     this.show_add=1
            // },
            cate_add(){
                this.$axios.post('cateM/',this.from).then(res=>{
                    if(res.data.code==200){
                        alert('添加成功')
                        this.show_add=0
                        this.get_cate()
                    }
                })
            },
            // show__s(id){
            //     this.show=1
            //     this.id=id
            // },
            get_cate(){
                this.$axios.get('cateM/').then(res=>{
                    this.frm = res.data.list
                })
            },
            // put_cate(){
            //     this.$axios.put('cateM/?id='+this.id+'&name='+this.name) 
            //     .then(res=>{
            //            console.log(res.data) 
            //            this.get_cate()

            //     })
 
            //     this.show=0
            // },
            del(id){
                this.$axios.delete('cateM/?id='+id)
                .then(res=>{
                     console.log(res.data)
                     alert('删除成功')
                     this.get_cate()
                })
            },
            // v形参，传递当前页数
            getlist(i){
                this.currentPage = i
                this.$axios.get('/cateF/?cpage='+i).then(res=>{
                this.list_1 = res.data.listt
                this.numm = res.data.total
                })
            },
            add(){
                this.$axios.post('cateF/',{name:this.name}).then(res=>{
                    if(res.data.code==200){
                        console.log(res.data)
                        alert('添加成功')
                    }
                })
            }
        },
        mounted(){
            this.get_cate()
            this.getlist(1)
        }
    }
</script>

<style scoped>

</style>